package com.fhz.kotlin_fun_test

import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import retrofit2.Retrofit

/**
 * 时间:2023/6/2
 * @author Mr.Feng
 * 简述: 内置函数, 协程
 */
fun main(){
    var mVar:Person = Person()

    //返回最后一行
    val let = mVar?.let {
        it.fun1()
        it.fun2()
        it.fun3()
        //最后一行
        "123"
    }
    //返回当前对象
    val also = mVar?.also {
        it.fun1()
        it.fun2()
        it.fun3()
        //最后一行
        "123"
    }

    //给一个对象的作用域
    with(mVar){
        fun1()
        fun2()
        fun3()
    }

    //结合了let、with的作用 ,返回最后一行
    val run = mVar?.run {
        fun1()
        fun2()
        fun3()
        10
    }
    println(run)

    //结合了also和wiht的作用,返回当前对象
    val apply = mVar?.apply {
        fun1()
        fun2()
        fun3()
    }
    println(apply)

    User(object : LoginCallBack{

        override fun loginSuccess() {
            //
            Loading(object : LoginCallBack{
                override fun loginSuccess() {

                }

                override fun loginFail() {
                }

            })
        }

        override fun loginFail() {
        }
    })

    GlobalScope.launch {
        val login = login()
        if(login){
            logding()
        }
    }


}



suspend fun login() : Boolean{
    //异步
    return true
}

suspend fun logding() : Boolean{
    //异步
    return true
}

interface LoginCallBack{
    fun loginSuccess()
    fun loginFail()
}

interface LogdingCallBack{
    fun loginSuccess()
}
class Loading(var loding:LoginCallBack)

class User(var loing: LoginCallBack)



class Person(var name:String="feng",var age:Int=18) {
    fun fun1(){ println("person fun1") }
    fun fun2(){ println("person fun2") }
    fun fun3(){ println("person fun3") }
}